
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using Andromeda.Global.Business;
using Andromeda.Global.Data.Db;
using Andromeda.Global.Common;
using ForgeIt.Dal.dbo.Validator;

  
namespace ForgeIt.Dal.dbo.Stub
{
	internal abstract class DBLicenseHistoryStub : dboSchema
	{
		#region private fields

		/// <summary>
		/// (fieldname, datatype, ischangeable(!isidentity), isinsertable(!isidentity), isforeignkey, foreigntable
		/// </summary>

		protected readonly DbField foIdLicenseHistory = new DbField("IdLicenseHistory", DbType.Int32, true, true, false, false, false, "");

		protected readonly DbField foIdLicense = new DbField("IdLicense", DbType.Int32, false, false, true, true, true, "License");

		protected readonly DbField foDescription = new DbField("Description", DbType.String, false, false, true, true, false, "");

		protected readonly DbField foBefore = new DbField("Before", DbType.String, false, false, true, true, false, "");

		protected readonly DbField foAfter = new DbField("After", DbType.String, false, false, true, true, false, "");

  
        #region local cache - Foreign Keys

        protected DBLicense localIdLicense;
  

        #endregion local cache - Foreign Keys


        #endregion private fields

        #region constructors

        protected DBLicenseHistoryStub()
		{
		}

		protected DBLicenseHistoryStub(bool ignorethis, string foDescription, string foBefore, string foAfter, Int32 foIdLicense)
		{

			this.foDescription.Value = foDescription;

			this.foBefore.Value = foBefore;

			this.foAfter.Value = foAfter;

			this.foIdLicense.Value = foIdLicense;

		}
	
		#endregion constructors
    
		#region public properties
		
		public override DbConnector CleanEntity
		{
			get { return new DBLicenseHistory(); }
		}


		public int IdLicenseHistory
		{
			get { return ObjectConverter.ToInt32(foIdLicenseHistory.Value); }
		}

		public int IdLicense
		{
			get { return ObjectConverter.ToInt32(foIdLicense.Value); }
			set { foIdLicense.Value = value; }
		}

		public string Description
		{
			get { return ObjectConverter.ToString(foDescription.Value); }
			set { foDescription.Value = value; }
		}

		public string Before
		{
			get { return ObjectConverter.ToString(foBefore.Value); }
			set { foBefore.Value = value; }
		}

		public string After
		{
			get { return ObjectConverter.ToString(foAfter.Value); }
			set { foAfter.Value = value; }
		}

  
		public override string TableName
		{
			get { return "LicenseHistory"; }
		}



        #region Foreign Keys
      
        /// <summary>
        /// Getter method for Object encapsulated view of foreign key
        /// </summary>
        public virtual DBLicense GetFK_IdLicense()
        {
          return localIdLicense ?? (localIdLicense = DBLicense.GetEntity(IdLicense));
        }
        /// <summary>
        /// Setter method for Object encapsulated view of foreign key
        /// </summary>        
        public virtual void SetFK_IdLicense(DBLicense paramIdLicense)
        {
          localIdLicense = paramIdLicense;
          IdLicense = paramIdLicense.IdLicense;
        }
      
        #endregion Foreign Keys


		    protected override ValidationModelBase Validator
		    {
			    get { return new DBLicenseHistoryValidator(); }
		    }
		#endregion public properties
    
		#region enumerator

		/// <summary>
		/// This enumerator contains a list of all the fields of the datasource
		/// </summary>
		public enum FieldNames
		{
			IdLicenseHistory,
			IdLicense,
			Description,
			Before,
			After,

		}

		#endregion enumerator
    
		#region generic field methods

		/// <summary>
		/// Validates if a given  field value is a DbNull
		/// </summary>
		/// <param name="fieldName">The field to validate</param>
		///<returns>true if is DbNull, false otherwise</returns>
		public bool IsDbNull(FieldNames fieldName)
		{
			switch (fieldName)
			{

				case FieldNames.IdLicenseHistory: return (foIdLicenseHistory.Value is DBNull);

				case FieldNames.IdLicense: return (foIdLicense.Value is DBNull);

				case FieldNames.Description: return (foDescription.Value is DBNull);

				case FieldNames.Before: return (foBefore.Value is DBNull);

				case FieldNames.After: return (foAfter.Value is DBNull);

			}

			throw new InvalidDataException();
		}

		/// <summary>
		/// Sets the given field value to DbNull
		/// </summary>
		/// <param name="fieldName">The field to set</param>
		public void SetDbNull(FieldNames fieldName)
		{
			switch (fieldName)
			{

				case FieldNames.IdLicenseHistory:
					foIdLicenseHistory.Value = DBNull.Value; break;

				case FieldNames.IdLicense:
					foIdLicense.Value = DBNull.Value; break;

				case FieldNames.Description:
					foDescription.Value = DBNull.Value; break;

				case FieldNames.Before:
					foBefore.Value = DBNull.Value; break;

				case FieldNames.After:
					foAfter.Value = DBNull.Value; break;

			}
		}
		
		#endregion generic field methods
    
        #region static factories

		/// <summary>
		/// Creates a new DB object that can be added to the database as a new row
		/// </summary>
		/// <returns>The instance of the DB Object</returns>
		public static DBLicenseHistory NewRow
		{
			get { return new DBLicenseHistory(); }
		}

		/// <summary>
		/// Returns multiple rows from the Datasource by a given set of WHERE clause fields, only includes fields where value != null
		/// </summary>
		/// <example>List of fields to filter by, null to ignore field (null = all).</example>
		/// <returns>A collection with the filtered results. </returns>
		internal static IEnumerable<DBLicenseHistory> ListEntity(object foIdLicenseHistory, object foIdLicense, object foDescription, object foBefore, object foAfter)
		{
			DBLicenseHistory helper = new DBLicenseHistory();
			

			helper.foIdLicenseHistory.Value = foIdLicenseHistory;

			helper.foIdLicense.Value = foIdLicense;

			helper.foDescription.Value = foDescription;

			helper.foBefore.Value = foBefore;

			helper.foAfter.Value = foAfter;


			return helper.GetEntityInstancesList(helper.Fields.ToArray()).Cast<DBLicenseHistory>();
        }

		/// <summary>
		/// Returns multiple rows from the Datasource by a given set of WHERE clause fields, only includes fields where value != null
		/// </summary>
		/// <example>List of fields to filter by, null to ignore field (null = all).</example>
		/// <returns>A collection with the filtered results. </returns>
		internal static IEnumerable<DBLicenseHistory> ListEntity()
		{
			return new DBLicenseHistory().GetEntityInstancesList(new DbField[0]).Cast<DBLicenseHistory>();
        }

      		/// <summary>
		/// Returns a single row from the datasource by a given set of RUID strong-typed values
		/// </summary>
		/// <returns>The instance for this key or a new one if no match is found.</returns>
		internal static DBLicenseHistory GetEntity(int foIdLicenseHistory)
		{
			DBLicenseHistory helper = new DBLicenseHistory();

			helper.foIdLicenseHistory.Value = foIdLicenseHistory;

			helper = helper.GetEntityInstance(helper.Ruid) as DBLicenseHistory;
			
			return helper;
		}


        /// <summary>
        /// Returns multiple rows from the Datasource that referentiate a specific foreign object 
        /// </summary>
        /// <param name="foIdLicense">The <see cref="DBLicense"/> object to filter by.</param>
        /// <returns>A collection with the filtered results.</returns>
        public static  IEnumerable<DBLicenseHistory> ListEntityIdLicense(DBLicense foIdLicense)
        {
          DBLicenseHistory helper = new DBLicenseHistory();

          helper.foIdLicense.Value = foIdLicense.IdLicense;

          return helper.GetEntityInstancesList(helper.foIdLicense).Cast<DBLicenseHistory>();
        }

		#endregion static factories
	}
}